package com.example.social.screen

import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.example.social.item_view.CommentItem
import com.example.social.screen.component.NotThreadList
import com.example.social.viewmodel.HomeViewModel


@Composable
fun NotificationComment(navHostController: NavHostController, uid: String) {
    val homeViewModel: HomeViewModel = viewModel()
    val context = LocalContext.current
    val comments by homeViewModel.comment.observeAsState(emptyList())
    if (uid.isNotEmpty()) {
        homeViewModel.getAllThreadCommentByUserId(uid)
    } else {
        Toast.makeText(context, "请求参数错误", Toast.LENGTH_SHORT).show()
    }

    Column(modifier = Modifier.padding(16.dp)){
        Text(
            text = "回复我的",
            fontSize = 24.sp,
            fontWeight = FontWeight.Bold,
            modifier = Modifier.padding(16.dp)
        )
        //下划线
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(1.dp)
                .width(15.dp)
                .background(Color.LightGray) // 自定义颜色
        )
        if (comments.isNotEmpty()) {
            LazyColumn(modifier = Modifier.fillMaxSize().padding(top=15.dp)) {
                items(comments) { comment ->
                    CommentItem(comment = comment, navHostController)
                }
            }
        } else {
            NotThreadList("暂无消息")
        }
    }
}